﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetEngine.Input;
using Microsoft.Xna.Framework.Input; 
#endregion

namespace DotNetEngine.Core
{
    public class TestGame : BaseGame
    {
        public delegate void RenderHandler();
        public RenderHandler initCode, updateCode, renderCode;
        public static TestGame Instance;

        #region Properties
        #endregion

        #region Initialize Methods
        public static void Start(string setWindowsTitle,
                                int windowWidth, int windowHeight,
                                RenderHandler setInitCode,
                                RenderHandler setUpdateCode,
                                RenderHandler setRenderCode)
        {
            using (TestGame game = new TestGame(setWindowsTitle,
                windowWidth, windowHeight, setInitCode, setUpdateCode, setRenderCode))
            {
                Instance = game;
                game.Run();
            }
        }

        public TestGame(string setWindowsTitle, int windowWidth, int windowHeight,
            RenderHandler setInitCode,
            RenderHandler setUpdateCode,
            RenderHandler setRenderCode)
        {
#if !XBOX360
            this.Window.Title = setWindowsTitle;
            if (windowWidth > 0 &&
                windowHeight > 0)
            {
                // Update width and height
                this.Window.BeginScreenDeviceChange(false);
                this.Window.EndScreenDeviceChange(this.Window.ScreenDeviceName, windowWidth, windowHeight);

                // Make sure our device is changed too (else the resolution
                // is not set for our 2d rendering).
                this.graphics.PreferredBackBufferWidth = windowWidth;
                this.graphics.PreferredBackBufferHeight = windowHeight;
                this.graphics.ApplyChanges();
            }
#endif

            initCode = setInitCode;
            updateCode = setUpdateCode;
            renderCode = setRenderCode;
        }

        protected override void InitializeGame()
        {
            if (initCode != null)
                initCode();
        }

        #endregion

        #region Public Methods
        public override void UpdateGame()
        {
            if (InputManager.KeyboardKeyPressed(Keys.Escape))
                Exit();

            if (updateCode != null)
                updateCode();
        }

        public override void DrawGame()
        {
            if (renderCode != null)
                renderCode();
        }

        #endregion

        #region Private Methods

        #endregion
    }
}


